package net.xdclass.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.xdclass.enums.BizCodeEnum;
import net.xdclass.request.LockCouponRecordRequest;
import net.xdclass.service.CouponRecordService;
import net.xdclass.service.CouponService;
import net.xdclass.util.JsonData;
import net.xdclass.vo.CouponRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 二当家小D
 * @since 2021-05-19
 */
@Api(tags = "优惠券流水")
@RestController
@RequestMapping("/api/coupon_record/v1")
public class CouponRecordController {
    @Autowired
    private CouponRecordService couponRecordService;

    @ApiOperation("分页查询个人优惠券")
    @GetMapping("page")
    public JsonData page(@RequestParam(value = "page",defaultValue = "1") int page,
                         @RequestParam(value = "size",defaultValue = "10") int size){
        Map<String,Object> map = couponRecordService.page(page,size);
        return JsonData.buildSuccess(map);
    }


    @ApiOperation("查询优惠券详情")
    @GetMapping("detail/{record_id}")
    public JsonData getDetail(@PathVariable("record_id") long recordId){
        CouponRecordVO couponRecordVO = couponRecordService.getDetail(recordId);
        return couponRecordVO==null?JsonData.buildResult(BizCodeEnum.COUPON_NO_EXITS):JsonData.buildSuccess(couponRecordVO);
    }

    public JsonData lockCouponRecord(@RequestBody LockCouponRecordRequest lockCouponRecordRequest) {
        JsonData jsonData = couponRecordService.lockCouponRecord(lockCouponRecordRequest);
        return jsonData;
    }
}


